<template>
	<view class="container">
		<text class="mark">{{mart}}分</text>
		<text class="tips">{{mart < 90 ? '很遗憾，考试不合格' : '恭喜，本次考试合格'}}</text>
		<view class="navigation">
			<view>
				<text>{{questionsLeft}}</text>
				<text>未做题</text>
			</view>
			<view>
				<text>{{wrongQuestions}}</text>
				<text>错题</text>
			</view>
			<view @click="exam">
				<image src="/static/kaoshi.png" mode="widthFix"></image>
				<text>重新考试</text>
			</view>
		</view>
	</view>
	<view class="container">
		<text class="mock-title">近20次模考成绩</text>
		<view class="history-score" v-for="(item,index) in scoreHistory" :key="index">
			<text>{{item.score}}分</text>
			<text>{{item.time}}</text>
		</view>
	</view>
</template>

<script setup>
	import {ref} from 'vue'
	import {onLoad} from '@dcloudio/uni-app'
	import {requestApi} from '@/api/request.js'
	const mart = ref(0)
	const questionsLeft = ref(0)
	const wrongQuestions = ref(0)
	const correctAnswers = ref(0)
	const scoreHistory = ref([])
	onLoad(async(event)=>{
		const analyze = JSON.parse(event.data)
		mart.value = analyze.mart
		questionsLeft.value = analyze.questionsLeft
		wrongQuestions.value = analyze.wrongQuestions
		correctAnswers.value = analyze.correctAnswers
		// 提交本次考试结果
		await requestApi('/examination-result',
		{correctFrequency:correctAnswers.value}
		)
		// 获取近20次的考试成绩
		const res = await requestApi('/gain-examination-result')
		scoreHistory.value = res.data
	})
	function exam(){
		wx.redirectTo({
			url:'/pages/exam-page/index'
		})
	}
</script>

<style>
	page{
		background-color: #f7f7f7;
	}
	text{
		display: block;
	}
	.container{
		background-color: #ffffff;
		border-radius: 10rpx;
		margin: 20rpx;
		padding: 20rpx;
	}
	.mark{
		text-align: center;
		color: #ec6655;
		font-size: 50rpx;
		font-weight: bold;
	}
	.tips{
		text-align: center;
		padding: 30rpx 0;
		font-weight: bold;
		font-size: 40rpx;
	}
	.navigation{
		display: flex;
		align-items: center;
		justify-content: space-around;
	}
	.navigation view{
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.navigation image{
		display: block;
		width: 50rpx;
	}
	.navigation text{
		padding: 5rpx 0;
	}
	.mock-title{
		font-size: 35rpx;
		font-weight: bold;
	}
	.history-score{
		display: flex;
		justify-content: space-between;
		padding: 25rpx 0;
		border-bottom: 1rpx solid #f4f4f4;
	}
	.history-score text:nth-child(1){
		color: #ec6655;
		font-weight: bold;
	}
</style>